﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_ZW_FAPIAORKJL实体层次
//********************************************************************************//
#region Entity
namespace Entity
{
    using System;
    using System.Xml;
    [Serializable()]
    public class YS_ZW_FAPIAORKJL
    {

        private decimal m_dec_id;
        /// <summary>
        /// 主键
        /// </summary>
        public decimal ID { get { return m_dec_id; } set { m_dec_id = value; } }

        private string m_str_s_qishihm;
        /// <summary>
        /// 起始号码
        /// </summary>
        public string S_QISHIHM { get { return m_str_s_qishihm; } set { m_str_s_qishihm = value; } }

        private string m_str_s_zhongzhihm;
        /// <summary>
        /// 终止号码
        /// </summary>
        public string S_ZHONGZHIHM { get { return m_str_s_zhongzhihm; } set { m_str_s_zhongzhihm = value; } }

        private decimal? m_dec_i_shuliang;
        /// <summary>
        /// 数量
        /// </summary>
        public decimal? I_SHULIANG { get { return m_dec_i_shuliang; } set { m_dec_i_shuliang = value; } }

        private string m_str_d_caozuor;
        /// <summary>
        /// 操作人
        /// </summary>
        public string D_CAOZUOR { get { return m_str_d_caozuor; } set { m_str_d_caozuor = value; } }

        private DateTime? m_DT_d_caozuosj;
        /// <summary>
        /// 操作时间
        /// </summary>
        public DateTime? D_CAOZUOSJ { get { return m_DT_d_caozuosj; } set { m_DT_d_caozuosj = value; } }

        private decimal? m_dec_i_jlzt;
        /// <summary>
        /// 0 正常 -1删除
        /// </summary>
        public decimal? I_JLZT { get { return m_dec_i_jlzt; } set { m_dec_i_jlzt = value; } }
        public YS_ZW_FAPIAORKJL()
        {
        }
    }
}
#endregion
#region EntityProcess
namespace BLL.Access
{
    using System;
    using System.Data;
    //using System.Data.OracleClient;
    using Entity;
    using System.Configuration;
    using System.Data.Common;
    using Platform.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    using Oracle.DataAccess;
    public class YS_ZW_FAPIAORKJLProcess
    {
        #region Field
        protected string conn;
        #endregion
        #region Construction
        public YS_ZW_FAPIAORKJLProcess() { conn = Platform.Configuration.ConfigHelper.PlatformConnString; }
        #endregion
        #region public

        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL实体添加或者修改YS_ZW_FAPIAORKJL信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL, OracleTransaction Transaction)
        {
            if (YS_ZW_FAPIAORKJL.ID == 0)
            {
                InsertYS_ZW_FAPIAORKJL(YS_ZW_FAPIAORKJL, Transaction);
            }
            else
            {
                UpdateYS_ZW_FAPIAORKJL(YS_ZW_FAPIAORKJL, Transaction);
            }
            return YS_ZW_FAPIAORKJL.ID == 0 ? false : true;
        }

        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL实体添加或修改YS_ZW_FAPIAORKJL信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL)
        {
            return InsertOrUpdate(YS_ZW_FAPIAORKJL, null);
        }



        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL主键删除YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_FAPIAORKJL(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_DelYS_ZW_FAPIAORKJL";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL主键删除YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_FAPIAORKJL(decimal ID)
        {
            return DeleteYS_ZW_FAPIAORKJL(ID, null);
        }

        /// <summary>
        /// 根据条件删除YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_FAPIAORKJLsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            string spName = "CS_DelYS_ZW_FAPIAORKJLsDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据条件删除YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_FAPIAORKJLsDynamic(string WhereClause)
        {
            return DeleteYS_ZW_FAPIAORKJLsDynamic(WhereClause, null);
        }

        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL主键选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public YS_ZW_FAPIAORKJL SelectYS_ZW_FAPIAORKJL(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_SelYS_ZW_FAPIAORKJL";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL = PopulateYS_ZW_FAPIAORKJL(rd);
                rd.Close();
                return YS_ZW_FAPIAORKJL;
            }
            else
                return null;
        }

        /// <summary>
        /// 根据YS_ZW_FAPIAORKJL主键选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public YS_ZW_FAPIAORKJL SelectYS_ZW_FAPIAORKJL(decimal ID)
        {
            return SelectYS_ZW_FAPIAORKJL(ID, null);
        }

        /// <summary>
        /// 选择所有YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsAll(OracleTransaction Transaction)
        {
            string spName = "CS_SelYS_ZW_FAPIAORKJLsAll";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }

        /// <summary>
        /// 选择所有YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <returns>所有YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsAll()
        {
            return SelectYS_ZW_FAPIAORKJLsAll(null);
        }

        /// <summary>
        /// 根据条件选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsDynamic(string WhereClause, string OrderByExpression, OracleTransaction Transaction)
        {
            string spName = "CS_SelYS_ZW_FAPIAORKJLsDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_ZW_FAPIAORKJLsDynamic(WhereClause, OrderByExpression, null);
        }



        /// <summary>
        /// 根据条件选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize, OracleTransaction Transaction)
        {
            string spName = "CS_SelYS_ZW_FAPIAORKJLsDynPaged";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择YS_ZW_FAPIAORKJL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_ZW_FAPIAORKJL信息</returns>
        public DataTable SelectYS_ZW_FAPIAORKJLsDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize)
        {
            return SelectYS_ZW_FAPIAORKJLsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///根据条件更新YS_ZW_FAPIAORKJL字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_FAPIAORKJLsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            int result = 0;
            if (UpdateValue == "" || WhereClause == "")
            {
                return 0;
            }
            string spName = "CS_UpdYS_ZW_FAPIAORKJLDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///根据条件更新YS_ZW_FAPIAORKJL字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_FAPIAORKJLsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_ZW_FAPIAORKJLsDynamic(UpdateValue, WhereClause, null);
        }


        #endregion
        #region Private

        private int InsertYS_ZW_FAPIAORKJL(YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL, OracleTransaction Transaction)
        {
            string spName = "CS_InsYS_ZW_FAPIAORKJL";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_FAPIAORKJL.S_QISHIHM;
            storedParams[1].Value = YS_ZW_FAPIAORKJL.S_ZHONGZHIHM;
            storedParams[2].Value = YS_ZW_FAPIAORKJL.I_SHULIANG;
            storedParams[3].Value = YS_ZW_FAPIAORKJL.D_CAOZUOR;
            storedParams[4].Value = YS_ZW_FAPIAORKJL.D_CAOZUOSJ;
            storedParams[5].Value = YS_ZW_FAPIAORKJL.I_JLZT;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_ZW_FAPIAORKJL.ID = Convert.ToInt32(storedParams[6].Value);
            return result;
        }
        private bool UpdateYS_ZW_FAPIAORKJL(YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL, OracleTransaction Transaction)
        {
            string spName = "CS_UpdYS_ZW_FAPIAORKJL";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_FAPIAORKJL.S_QISHIHM;
            storedParams[1].Value = YS_ZW_FAPIAORKJL.S_ZHONGZHIHM;
            storedParams[2].Value = YS_ZW_FAPIAORKJL.I_SHULIANG;
            storedParams[3].Value = YS_ZW_FAPIAORKJL.D_CAOZUOR;
            storedParams[4].Value = YS_ZW_FAPIAORKJL.D_CAOZUOSJ;
            storedParams[5].Value = YS_ZW_FAPIAORKJL.I_JLZT;
            storedParams[6].Value = YS_ZW_FAPIAORKJL.ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_ZW_FAPIAORKJL PopulateYS_ZW_FAPIAORKJL(IDataReader dr)
        {
            YS_ZW_FAPIAORKJL YS_ZW_FAPIAORKJL = new YS_ZW_FAPIAORKJL();
            YS_ZW_FAPIAORKJL.ID = dr["ID"] == DBNull.Value ? (decimal)0 : (decimal)dr["ID"];
            YS_ZW_FAPIAORKJL.S_QISHIHM = dr["S_QISHIHM"] == DBNull.Value ? null : (string)dr["S_QISHIHM"];
            YS_ZW_FAPIAORKJL.S_ZHONGZHIHM = dr["S_ZHONGZHIHM"] == DBNull.Value ? null : (string)dr["S_ZHONGZHIHM"];
            YS_ZW_FAPIAORKJL.I_SHULIANG = dr["I_SHULIANG"] == DBNull.Value ? null : (decimal?)dr["I_SHULIANG"];
            YS_ZW_FAPIAORKJL.D_CAOZUOR = dr["D_CAOZUOR"] == DBNull.Value ? null : (string)dr["D_CAOZUOR"];
            YS_ZW_FAPIAORKJL.D_CAOZUOSJ = dr["D_CAOZUOSJ"] == DBNull.Value ? null : (DateTime?)dr["D_CAOZUOSJ"];
            YS_ZW_FAPIAORKJL.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?)dr["I_JLZT"];
            return YS_ZW_FAPIAORKJL;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
            }
        }
        #endregion
    }
}
#endregion